package com.virtualtrainer_01.view;

import android.app.Activity;
import android.content.Intent;
import android.database.SQLException;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;

import com.virtualtrainer_01.R;
import com.virtualtrainer_01.dao.ClientDB;
import com.virtualtrainer_01.dao.SQLiteWrite;

public class Menu extends Activity implements OnClickListener {

	String activities[] = { "EXERCISES", "GENERATE", "SETUP", "PROGRESS" };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);

		SQLiteWrite sqlw = new SQLiteWrite(Menu.this);
		String numeClient = null;
		try {
			ClientDB cdb = new ClientDB(Menu.this);
			cdb.open();
			numeClient = cdb.getName();
			cdb.close();
			if (numeClient == null) {
				Intent i = new Intent("android.intent.action.CLIENTINFO");
				startActivity(i);
				finish();
			}
		} catch (SQLException e1) {
			sqlw.populate();
			e1.printStackTrace();
			Intent i = new Intent("android.intent.action.CLIENTINFO");
			startActivity(i);
			finish();
		}
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		for (int i = 0; i < activities.length; i++) {
			if (id == v.getResources().getIdentifier("b" + i, "id", "com.virtualtrainer_01")) {
				Intent intent = new Intent("com.virtualtrainer_01.view." + activities[i]);
				startActivity(intent);
			}
		}
	}

	@Override
	public boolean onCreateOptionsMenu(android.view.Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.action_settings:
			
			break;
		case R.id.action_my_profile:
			
			break;
		case R.id.action_update:
			
			break;
		case R.id.action_about:
			
			break;

		}
		return super.onOptionsItemSelected(item);
	}
}
